//
//  BKOrderPaymentViewController.m
//  bestkeep
//
//  Created by 马乾征 on 16/11/10.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKOrderPaymentViewController.h"
#import "BK_Account_Recharge_VC.h"
#import "BK_Confirm_Order_VC.h"
#import "BKODAliManager.h"
#import "BKODWXManager.h"
#import "WXApiManager.h"
#import "BK_Order_PayModel.h"
#import "BK_Pay_Tool.h"
#import "BK_OD_Color.h"
#define ODWXPay   @"isWXPay"
#define ODAliPay  @"isAliPay"

@interface BKOrderPaymentViewController ()
<
UITableViewDelegate,
UITableViewDataSource,
BKODWXManagerDelegate,
BKODAliManagerDelegate,
BKOrderPaymentNowViewDelegate,
BKOrderPaymentTimeLimitTableHeaderViewDelegate,
WXApiManagerDelegate,
UIAlertViewDelegate
>

@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)BKOrderPaymentNowView *paymentFooterView;
@property(nonatomic, strong)BKOrderPaymentTimeLimitTableHeaderView *tableHeadView;
@property(nonatomic, strong)ExceptionView *exceptionView;
@property(nonatomic, strong)NSArray *dataArray;

@property(nonatomic, assign)BOOL isAliPay;
@property(nonatomic, assign)BOOL isWXPay;
@property(nonatomic, assign)BOOL isZeroRMBOrder;

@property(nonatomic, strong)BK_Order_PayModel*model_payType;

@property(nonatomic, assign)BOOL isPayMethod;//支付方式
@property(nonatomic, assign)BOOL isPayTimes;//剩余付款时间
//@property(nonatomic, assign)BOOL isNeedMoney;//实付金额
@property(nonatomic, assign)BOOL isTotalMoney;//总金额
@end

@implementation BKOrderPaymentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setProperty];
    [self createUI];
    [self check_NetWork];
}
#pragma mark==================setProperty======================
-(void)setProperty{
    /*
     * 支付订单页面
     */
    self.view.backgroundColor = ThemeBackgroundColor;
    self.navigationItem.title = kOrderLocalizeString(@"BKOrderPayControllerTitle");
    _isPayMethod=NO;//支付方式
    _isPayTimes=NO;//剩余付款时间
    //    _isNeedMoney=NO;//实付金额
    _isTotalMoney=NO;//总金额
}
#pragma mark==================createUI======================
-(void)createUI{
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    _tableView.tableFooterView = [[UIView alloc] init];
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.separatorInset = UIEdgeInsetsZero;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    _tableHeadView = [[BKOrderPaymentTimeLimitTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, kOrderScreenWidth, 20)];
    _tableHeadView.delegate = self;
    _tableView.tableHeaderView = _tableHeadView;
    
    _paymentFooterView = [[BKOrderPaymentNowView alloc] init];
    _paymentFooterView.delegate = self;
    [self.view addSubview:_paymentFooterView];
    
    [self layoutUI];
}
#pragma mark==================布局======================
- (void)layoutUI{
    
    [_paymentFooterView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self.view);
        make.height.mas_equalTo(44);
    }];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view);
        make.left.right.mas_equalTo(self.view);
        make.bottom.mas_equalTo(_paymentFooterView.mas_top);
    }];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    /*
     * 请求订单支付时间
     */
    [self BK_Pay_get_CanPayTimes];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
#pragma mark==================checkNet======================
-(void)check_NetWork{
    RequestReachabilityStatus status = [RequestManager reachabilityStatus];
    switch (status) {
        case RequestReachabilityStatusReachableViaWiFi:
        case RequestReachabilityStatusReachableViaWWAN: {
            /*
             * 获取支付方式
             */
            [self BK_Pay_get_PayMethod];
            /*
             * 请求订单实付金额
             */
            
            [self BK_Order_total_Money];
            
        }
            break;
        default: {
            [HUD dismiss];
            
            self.exceptionView = [ExceptionView exceptionViewWithType:ExceptionCodeTypeNoNetwork];
            ExceptionViewAction *action = [ExceptionViewAction actionWithType:ExceptionCodeTypeNoNetwork handler:^(ExceptionViewAction *action) {
                [self.exceptionView dismiss];
                self.exceptionView = nil;
                [self check_NetWork];
            }];
            [self.exceptionView addAction:action];
            [self.exceptionView showInView:self.view];
        }
            break;
    }
}



#pragma mark==================请求订单支付时间======================
- (void)BK_Pay_get_CanPayTimes{
    [BK_Pay_Tool BK_Order_CanPayTimes:^(BOOL isSuccess, id obj, NSError *error) {
        _isPayTimes=YES;
        if (isSuccess) {
            NSNumber *timeLimit = obj[@"data"][@"canPayTimes"];
            [_tableHeadView setTimeLimit:timeLimit];
        }
    } WithOrderNum:_orderNumber];
}

#pragma mark==================请求订单支持支付方式======================
- (void)BK_Pay_get_PayMethod{
    
    
    [BKIndicationView showInView:self.view];
    NSString *const ODPayLimitInfo = @"pay/limit-info";
    [[RequestManager manager] bkDataRequest:RequestMethodPost URLString:kOrderURL(ODPayLimitInfo) parameters:nil
                                    success:^(id  _Nullable responseObject){
                                        _isPayMethod=YES;
                                        BOOL success = [responseObject[@"success"] boolValue];
                                        if (!success) {
                                            [BKIndicationView dismiss];
                                            kOrderPromptMsg(responseObject[@"msg"]);
                                            return;
                                        }else{
                                            if (_isPayTimes&&_isPayMethod&&_isTotalMoney) {
                                                [BKIndicationView dismiss];
                                            }
                                            NSDictionary *data = responseObject[@"data"];
                                            _model_payType=[BK_Order_PayModel mj_objectWithKeyValues:data];
                                            _isAliPay = [_globalStatus boolValue] ? [_model_payType.global_order_alipay boolValue] : [_model_payType.inland_order_alipay boolValue];
                                            //微信暂不支持跨境淘
                                            _isWXPay = [_globalStatus boolValue] ? NO : [_model_payType.inland_wx_pay boolValue];
                                            //账户余额不支持跨境淘
                                            [_globalStatus boolValue] ? [self create_Section_WithAccount:nil] : [self BK_Pay_AccountBalance];
                                        }
                                        
                                    }failure:^(id  _Nullable responseObject, NSError * _Nullable error){
                                        _isPayMethod=YES;
                                        [BKIndicationView dismiss];
                                        NSString *errorMsg;
                                        if (error.code == -1001) {
                                            errorMsg = @"请求超时";
                                        }else if(error.code == 502){
                                            errorMsg = @"服务器开小差了，请稍后再试！";
                                        }else{
                                            errorMsg = @"请求失败";
                                        }
                                        kOrderPromptMsg(errorMsg);
                                    }];
    
    
}

#pragma mark==================请求账户余额======================
- (void)BK_Pay_AccountBalance{
    
    NSString *const ODAccountBalance = @"account/balance";
    [BKIndicationView showInView:self.view];
    [[RequestManager manager] bkDataRequest:RequestMethodPost URLString:kOrderURL(ODAccountBalance) parameters:nil
                                    success:^(id  _Nullable responseObject){
                                        BOOL success = [responseObject[@"success"] boolValue];
                                        if (!success) {
                                            [BKIndicationView dismiss];
                                            kOrderPromptMsg(responseObject[@"msg"]);
                                            return;
                                        }else{
                                            [BKIndicationView dismiss];
                                            NSDictionary *accountInfo = [responseObject[@"data"][@"account"] firstObject];
                                            BKODPaymentAccount *account = [BKODPaymentAccount mj_objectWithKeyValues:accountInfo];
                                            [self create_Section_WithAccount:account];
                                        }
                                        
                                    }failure:^(id  _Nullable responseObject, NSError * _Nullable error){
                                        [BKIndicationView dismiss];
                                        NSString *errorMsg;
                                        if (error.code == -1001) {
                                            errorMsg = @"请求超时";
                                        }else if(error.code == 502){
                                            errorMsg = @"服务器开小差了，请稍后再试！";
                                        }else{
                                            errorMsg = @"请求失败";
                                        }
                                        kOrderPromptMsg(errorMsg);
                                    }];
    
    
    
    
}

#pragma mark==================创建Section数据======================
- (void)create_Section_WithAccount:(BKODPaymentAccount *)account{
    NSMutableArray *cellArr = [NSMutableArray array];
    NSMutableArray *sectionArr = [NSMutableArray array];
    
    if (account) {
        
        CellModel *s0c0 = [[CellModel alloc] init];
        s0c0.className = NSStringFromClass([BKOrderAccountBlancePaymentCell class]);
        s0c0.height = [BKOrderAccountBlancePaymentCell computeHeight:nil];
        s0c0.reuseIdentifier = @"s0c0";
        s0c0.userInfo = account;
        [cellArr addObject:s0c0];
    }
    if (_isAliPay) {
        
        CellModel *s0c1 = [[CellModel alloc] init];
        s0c1.className = NSStringFromClass([BKOrderOtherPaymentCell class]);
        s0c1.height = [BKOrderOtherPaymentCell computeHeight:nil];
        s0c1.reuseIdentifier = @"s0c1";
        s0c1.userInfo = ODAliPay;
        [cellArr addObject:s0c1];
    }
    if (_isWXPay) {
        
        CellModel *s0c2 = [[CellModel alloc] init];
        s0c2.className = NSStringFromClass([BKOrderOtherPaymentCell class]);
        s0c2.height = [BKOrderOtherPaymentCell computeHeight:nil];
        s0c2.reuseIdentifier = @"s0c2";
        s0c2.userInfo = ODWXPay;
        [cellArr addObject:s0c2];
    }
    
    SectionModel *s0 = [SectionModel sectionModelWithTitle:nil cells:cellArr.copy];
    s0.className = NSStringFromClass([BKOrderPaymentSectionHeaderView class]);
    s0.reuseIdentifier = @"s0";
    s0.headerhHeight = [BKOrderPaymentSectionHeaderView computeHeight:nil];
    s0.userInfo = @{@"title" : @"支付方式"};
    s0.footerHeight = 0.1;
    
    [sectionArr addObject:s0];
    
    _dataArray = nil;
    _dataArray = sectionArr.copy;
    
    [_tableView reloadData];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(100 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
        [_tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    });
}

#pragma mark-订单总金额计算
-(void)BK_Order_total_Money{
    
    NSString * const strOrder_total = @"order/total";
    [BKIndicationView showInView:self.view];
    NSDictionary *paramDic = @{
                               @"order_no"          : _orderNumber,
                               @"shopping_tickets"  : @"",
                               @"sugar_amount"      : @"0.0"
                               };
    
    [[RequestManager manager] bkDataRequest:RequestMethodPost URLString:kOrderURL(strOrder_total) parameters:paramDic
     
                                    success:^(id  _Nullable responseObject){
                                        _isTotalMoney=YES;
                                        if (_isPayTimes&&_isPayMethod&&_isTotalMoney) {
                                            [BKIndicationView dismiss];
                                        }
                                        BOOL success = [responseObject[@"success"] boolValue];
                                        if (!success) {
                                            [BKIndicationView dismiss];
                                            kOrderPromptMsg(responseObject[@"msg"]);
                                            [_paymentFooterView setCanPayment:NO];
                                            return;
                                        }else{
                                            [BKIndicationView dismiss];
                                            NSNumber *actuallyAmount = responseObject[@"data"][@"total_amount"];
                                            [_paymentFooterView setPaymentWithAmount:actuallyAmount];
                                            [_paymentFooterView setCanPayment:YES];
                                            
                                            [self BK_Calculate_need_money];
                                        }
                                    } failure:^(id  _Nullable responseObject, NSError * _Nullable error){
                                        _isTotalMoney=YES;
                                        [BKIndicationView dismiss];
                                        NSString *errorMsg;
                                        if (error.code == -1001) {
                                            errorMsg = @"请求超时";
                                        }else if(error.code == 502){
                                            errorMsg = @"服务器开小差了，请稍后再试！";
                                        }else{
                                            errorMsg = @"请求失败";
                                        }
                                        kOrderPromptMsg(errorMsg);
                                    }];
    
    
    
    
}

#pragma mark==================请求订单实付金额======================
-(void)BK_Calculate_need_money{
    
    NSString *const ODRealPayAmount = @"pay/calc-actually-amount";
    [BKIndicationView showInView:self.view];
    NSDictionary *paramDic = @{
                               @"order_no"          : _orderNumber,
                               @"shopping_tickets"  : @"",
                               @"sugar_amount"      : @"0.0"
                               };
    
    [[RequestManager manager] bkDataRequest:RequestMethodPost URLString:kOrderURL(ODRealPayAmount) parameters:paramDic
     
                                    success:^(id  _Nullable responseObject){
                                        BOOL success = [responseObject[@"success"] boolValue];
                                        if (!success) {
                                            [BKIndicationView dismiss];
                                            kOrderPromptMsg(responseObject[@"msg"]);
                                            return;
                                        }else{
                                            [BKIndicationView dismiss];
                                            NSNumber *actuallyAmount = responseObject[@"data"][@"actuallyAmount"];
                                            [_paymentFooterView setPaymentWithAmount:actuallyAmount];
                                            [_paymentFooterView setCanPayment:YES];
                                            
                                        }
                                    } failure:^(id  _Nullable responseObject, NSError * _Nullable error){
                                        
                                        [BKIndicationView dismiss];
                                        NSString *errorMsg;
                                        if (error.code == -1001) {
                                            errorMsg = @"请求超时";
                                        }else if(error.code == 502){
                                            errorMsg = @"服务器开小差了，请稍后再试！";
                                        }else{
                                            errorMsg = @"请求失败";
                                        }
                                        kOrderPromptMsg(errorMsg);
                                    }];
    
    
    
    
}


#pragma mark  tableView 代理相关

/**
 section
 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _dataArray.count;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    SectionModel *sm = _dataArray[section];
    
    BKOrderPaymentHeaderFooterView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:sm.reuseIdentifier];
    if (!headerView) {
        headerView = [[NSClassFromString(sm.className) alloc] initWithReuseIdentifier:sm.reuseIdentifier];
    }
    return headerView;
}

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    SectionModel *sm = _dataArray[section];
    
    BKOrderPaymentHeaderFooterView *headView = (BKOrderPaymentHeaderFooterView *)view;
    
    SEL selector = NSSelectorFromString(@"fillData:");
    if ([headView respondsToSelector:selector])
    {
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Warc-performSelector-leaks"
        [headView performSelector:selector withObject:sm.userInfo];
#pragma clang diagnostic pop
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    SectionModel *sm = _dataArray[section];
    
    return sm.headerhHeight;
}

/**
 cell
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    SectionModel *sm = _dataArray[section];
    
    return sm.cells.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SectionModel *sm = _dataArray[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    
    BKOrderPaymentCell *cell = [tableView dequeueReusableCellWithIdentifier:cm.reuseIdentifier];
    
    if (!cell){
        cell = [[NSClassFromString(cm.className) alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cm.reuseIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    SectionModel *sm = _dataArray[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    
    BKOrderPaymentCell *BKCell = (BKOrderPaymentCell *)cell;
    
    SEL selector = NSSelectorFromString(@"fillData:");
    if ([BKCell respondsToSelector:selector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Warc-performSelector-leaks"
        [BKCell performSelector:selector withObject:cm.userInfo];
#pragma clang diagnostic pop
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SectionModel *sm = _dataArray[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    
    SEL selector = NSSelectorFromString(cm.selectorString);
    if ([self respondsToSelector:selector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Warc-performSelector-leaks"
        [self performSelector:selector withObject:indexPath];
#pragma clang diagnostic pop
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    SectionModel *sm = _dataArray[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    
    return cm.height;
}
#pragma mark  订单限制时间结束回调
- (void)orderPaymentTimeOut{
    [_paymentFooterView setCanPayment:NO];
}


#pragma mark 立即支付
- (void)orderPaymentNowViewDidSelected:(BKOrderPaymentNowView *)paymentNowView
{
    NSIndexPath *indexPath = [_tableView indexPathForSelectedRow];
    if (!indexPath) {
        kOrderPromptMsg(@"未选择支付方式");
        return;
    }
    
    if ([RequestManager reachabilityStatus] == RequestReachabilityStatusUnknown || [RequestManager reachabilityStatus] == RequestReachabilityStatusNotReachable) {
        kOrderPromptMsg(@"请检查您的网络");
        return;
    }
    
    SectionModel *sm = _dataArray[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    
    NSString *aCellClassName = NSStringFromClass([BKOrderAccountBlancePaymentCell class]);
    
    if ([cm.className isEqualToString:aCellClassName]) {
        //余额支付
        double amount = [_paymentFooterView.amount doubleValue];
        BKODPaymentAccount *account = cm.userInfo;
        double accountBalance = [account.account_balance doubleValue];
        if (amount > accountBalance) {
            kOrderDismiss;
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"账号余额不足，请充值" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去充值", nil];
            [alertView show];
            return;
        }
        [self BK_Pay_Use_AccountBalance];
    }else{
        //其他支付
        if ([cm.userInfo isEqualToString:ODAliPay]) {
            [self AliPay];
        }else if ([cm.userInfo isEqualToString:ODWXPay]){
            [self WXPay];
        }
    }
    
}

#pragma mark-------------余额支付-------------
- (void)BK_Pay_Use_AccountBalance{
    [BK_Pay_Tool BK_Pay_order:^(BOOL isSuccess, id obj, NSError *error) {
        if (isSuccess) {
            BKOrderPayForResultsViewController *resultVC = [[BKOrderPayForResultsViewController alloc] init];
            resultVC.hidesBottomBarWhenPushed = YES;
            resultVC.orderNumber = _orderNumber;
            resultVC.globalStatus = _globalStatus;
            resultVC.success = isSuccess;
            [self.navigationController pushViewController:resultVC animated:YES];
        }
    } WithOrderNum:_orderNumber];
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {//去充值
        [self goTop_upMoney];
    }
}
//去充值
- (void)goTop_upMoney
{
    BK_Account_Recharge_VC *brVC = [[BK_Account_Recharge_VC alloc] init];
    [self.navigationController pushViewController:brVC animated:YES];
}

#pragma mark---------支付宝支付----------------
- (void)AliPay{
    [BK_Pay_Tool BK_AliPay:^(BOOL isSuccess, id obj, NSError *error) {
        if (isSuccess) {
            NSString *payInfo = obj[@"data"][@"pay_info"];
            //调支付宝
            [BKODAliManager manager].delegate = self;
            [[BKODAliManager manager] payRequestOrderString:payInfo];
        }
    } WithOrderNum:_orderNumber andGlobalStatus:_globalStatus];
}

#pragma mark==================支付宝支付结果回调======================
- (void)ODWAliManagerDidRecvPayResult:(NSDictionary *)resultDic{
    
    BKOrderPayForResultsViewController *resultVC = [[BKOrderPayForResultsViewController alloc] init];
    resultVC.hidesBottomBarWhenPushed = YES;
    
    if ([resultDic[@"resultStatus"] isEqualToString:@"9000"]) {//支付成功
        resultVC.success = YES;
    }
    resultVC.orderNumber = _orderNumber;
    resultVC.globalStatus = _globalStatus;
    [_tableHeadView timerInvalidate];
    [self.navigationController pushViewController:resultVC animated:YES];
}

#pragma mark---------微信支付----------------
- (void)WXPay{
    [BK_Pay_Tool BK_WX_Pay_Info:^(BOOL isSuccess, id obj, NSError *error) {
        if (isSuccess) {
            NSString *payInfo = obj[@"data"][@"pay_info"];
            NSDictionary *payInfoDic = [NSJSONSerialization JSONObjectWithData:[NSData dataWithBytes:[payInfo UTF8String] length:payInfo.length] options:NSJSONReadingMutableLeaves error:nil];
            
            BKODWXObject *obj = [[BKODWXObject alloc] init];
            obj.nonceStr = payInfoDic[@"noncestr"];
            obj.package = payInfoDic[@"package"];
            obj.partnerId = payInfoDic[@"partnerid"];
            obj.prepayId = payInfoDic[@"prepayid"];
            obj.sign = payInfoDic[@"sign"];
            obj.timeStamp = (UInt32)[payInfoDic[@"timestamp"] intValue];
            
            //调微信支付
            [WXApi registerApp:@"wx2c7367321c4ecab5"];
            [WXApiManager sharedManager].delegate = self;
            PayReq *req     = [[PayReq alloc] init];
            req.nonceStr    = obj.nonceStr;
            req.package     = obj.package;
            req.partnerId   = obj.partnerId;
            req.prepayId    = obj.prepayId;
            req.sign        = obj.sign;
            req.timeStamp   = obj.timeStamp;
            [WXApi sendReq:req];
            
        }
    } WithOrderNum:_orderNumber];
    
}



#pragma mark==================微信支付结果回调======================
- (void)managerDidRecvPayResponse:(PayResp *)response{
    [self ODWXManagerDidRecvPayResponse:response];
}
//微信支付结果回调
- (void)ODWXManagerDidRecvPayResponse:(PayResp *)response{
    BKOrderPayForResultsViewController *resultVC = [[BKOrderPayForResultsViewController alloc] init];
    resultVC.hidesBottomBarWhenPushed = YES;
    
    if (response.errCode == 0) {//支付成功
        resultVC.success = YES;
    }
    resultVC.orderNumber = _orderNumber;
    resultVC.globalStatus = _globalStatus;
    [_tableHeadView timerInvalidate];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(500 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
        [self.navigationController pushViewController:resultVC animated:YES];
    });
}
- (void)dealloc{
    [BKODWXManager manager].delegate = nil;
    [WXApiManager sharedManager].delegate = nil;
}
@end















